package cn.bdqn.yan;

import cn.bdqn.yan.pojo.Category;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.InputStream;
import java.util.List;

public class Main {

    public static void main(String[] args) throws Exception {
        String resource = "mybatis-config.xml";
        InputStream inputStream = Resources.getResourceAsStream(resource);
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        SqlSession session = sqlSessionFactory.openSession();
        //List<Category> categories = session.selectList("cn.bdqn.yan.mapper.CategoryMapper.listcategory");
       /* List<Category> categories = session.selectList("listcategory");
        for (Category c : categories) {
            System.out.println(c.getId()+":"+c.getName());
        }*/
        //查询category表中的数据个数
        /*int nums = 0;
        nums = session.selectOne("cn.bdqn.yan.mapper.CategoryMapper.getcount");
        System.out.println("category表中的数据总共有" + nums + "条");*/
//        int nums=(Integer) session.selectList("getcount");
//        System.out.println("num:"+nums);
         //查询表中性别为女的信息列表
        List<Category> listbysex=session.selectList("listcategorybysex");
        System.out.println("性别为女的所有人员如下");
        for (Category c : listbysex) {
            System.out.println(c.getId()+":"+c.getName()+" "+c.getSex());
        }

    }


}
